package com.sc.controller.Vast_controller;

import com.sc.Vast_pojo.domain.DeviceFix;
import com.sc.Vast_pojo.dto.DeviceFixDTO;
import com.sc.Vast_pojo.dto.DeviceFixPageQueryDTO;
import com.sc.result.PageResult;
import com.sc.result.Result;
import com.sc.service.Vast_service.DeviceFixService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Vast
 * @version 1.0
 * @function:设备维修记录控制层
 */
@Api(tags = "设备维修记录相关接口")
@RestController
@RequestMapping("/DeviceFix")
@Slf4j
@CrossOrigin
public class DeviceFixController {
    @Autowired
    private DeviceFixService deviceFixService;

    /**
     * 设备维修记录分页查询
     *
     * @param deviceFixDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("设备维修记录分页查询")
    public Result<PageResult> pageQuery(DeviceFixPageQueryDTO deviceFixPageQueryDTO) {
        log.info("设备维修记录分页查询,{}", deviceFixPageQueryDTO);
        PageResult pageResult = deviceFixService.pageQuery(deviceFixPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据主键id查询工单详细
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据主键id查询工单详细")
    public Result<DeviceFix> getById(@PathVariable("id") Integer id) {
        DeviceFix deviceGroup = deviceFixService.getById(id);
        return Result.success(deviceGroup);
    }

    /**
     * 新建维修工单
     *
     * @param deviceFixDTO
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新建维修工单")
    public Result save(@RequestBody DeviceFixDTO deviceFixDTO) {
        log.info("新建维修工单：{}", deviceFixDTO);
        deviceFixService.save(deviceFixDTO);
        return Result.success(null, "添加成功");
    }

    /**
     * 根据主键更新维修工单
     *
     * @param deviceFixDTO
     * @param id
     * @return
     */
    @PostMapping("/updateDeviceFix")
    @ApiOperation("更新主键维修工单")
    public Result update(@RequestBody DeviceFixDTO deviceFixDTO, Integer id) {
        log.info("更新维修工单，{},{}", id, deviceFixDTO);
        deviceFixService.update(deviceFixDTO, id);
        return Result.success(null, "更新成功");
    }

    /**
     * 设备维修记录删除
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("设备维修记录删除")
    public Result delete(@PathVariable Integer id) {
        log.info("设备维修记录删除,{}", id);
        deviceFixService.delete(id);
        return Result.success(null, "删除成功");
    }

    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        deviceFixService.removeByIds(ids);
        return Result.success();
    }
}
